package com.mzy.datepackage.M2022.Apr.twFour;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author mzy
 * @Date 2022/4/24 16:49
 * @Version 1.0
 */
public class test2 {
    public static void main(String[] args) {
        String s = Transform_to_Binary(4,"");
        System.out.println(s);
        int i = binaryGap(Integer.parseInt(s));
    }

    static public String Transform_to_Binary(int decimal,String binary) {
        if(decimal==0){
            return binary;
        }
        else {
            binary+=decimal%2;
            Transform_to_Binary(decimal/2,binary);

        }
        return binary;
    }

    public static int binaryGap(int n) {
        int ans = 0;
        for (int i = 31, j = -1; i >= 0; i--) {
            if (((n >> i) & 1) == 1) {
                if (j != -1) ans = Math.max(ans, j - i);
                j = i;
            }
        }
        return ans;
    }

}
